using System;
using System.Collections.Generic;


namespace LiveCS.Models
{
	[Serializable]
	public class User: IEquatable<User>
	{

		#region Private Members

		private string _userid; 
		private IList<Userlog> _UserlogList; 
		private IList<Consumemoney> _ConsumemoneyList; 
		private string _username; 
		private string _userpwd; 
		private string _usersex; 
		private string _userrole; 
		private string _remark; 		
		#endregion

		#region Constructor

		public User()
		{
			_userid = String.Empty; 
			_UserlogList = new List<Userlog>(); 
			_ConsumemoneyList = new List<Consumemoney>(); 
			_username = String.Empty; 
			_userpwd = String.Empty; 
			_usersex = String.Empty; 
			_userrole = String.Empty; 
			_remark = String.Empty; 
		}
		#endregion // End of Default ( Empty ) Class Constuctor

		#region Required Fields Only Constructor
		/// <summary>
		/// required (not null) fields only constructor
		/// </summary>
		public User(
			string userid)
			: this()
		{
			_userid = userid;
			_username = String.Empty;
			_userpwd = String.Empty;
			_usersex = String.Empty;
			_userrole = String.Empty;
			_remark = String.Empty;
		}
		#endregion // End Constructor

		#region Public Properties
			
		public virtual string Userid
		{
			get
			{ 
				return _userid;
			}

			set	
			{	
				if( value == null )
					throw new ArgumentOutOfRangeException("Null value not allowed for Userid", value, "null");
				
				if(  value.Length > 40)
					throw new ArgumentOutOfRangeException("Invalid value for Userid", value, value.ToString());
				
				_userid = value;
			}
		}
			
		public virtual IList<Userlog> UserlogList
		{
			get
			{
				return _UserlogList;
			}
			set
			{
				_UserlogList = value;
			}
		}

		public virtual IList<Consumemoney> ConsumemoneyList
		{
			get
			{
				return _ConsumemoneyList;
			}
			set
			{
				_ConsumemoneyList = value;
			}
		}

		public virtual string UserName
		{
			get
			{ 
				return _username;
			}

			set	
			{	
				if(  value != null &&  value.Length > 40)
					throw new ArgumentOutOfRangeException("Invalid value for UserName", value, value.ToString());
				
				_username = value;
			}
		}
			
		public virtual string UserPwd
		{
			get
			{ 
				return _userpwd;
			}

			set	
			{	
				if(  value != null &&  value.Length > 40)
					throw new ArgumentOutOfRangeException("Invalid value for UserPwd", value, value.ToString());
				
				_userpwd = value;
			}
		}
			
		public virtual string UserSex
		{
			get
			{ 
				return _usersex;
			}

			set	
			{	
				if(  value != null &&  value.Length > 2)
					throw new ArgumentOutOfRangeException("Invalid value for UserSex", value, value.ToString());
				
				_usersex = value;
			}
		}
			
		public virtual string UserRole
		{
			get
			{ 
				return _userrole;
			}

			set	
			{	
				if(  value != null &&  value.Length > 40)
					throw new ArgumentOutOfRangeException("Invalid value for UserRole", value, value.ToString());
				
				_userrole = value;
			}
		}
			
		public virtual string Remark
		{
			get
			{ 
				return _remark;
			}

			set	
			{	
				if(  value != null &&  value.Length > 100)
					throw new ArgumentOutOfRangeException("Invalid value for Remark", value, value.ToString());
				
				_remark = value;
			}
		}
			
				
		#endregion 

		#region Public Functions

		public virtual void AddUserlog(Userlog obj)
		{
			#region Check if null
			if (obj == null)
				throw new ArgumentNullException("obj", "El parametro no puede ser nulo");
			#endregion
			_UserlogList.Add(obj);
		}
		

		public virtual void AddConsumemoney(Consumemoney obj)
		{
			#region Check if null
			if (obj == null)
				throw new ArgumentNullException("obj", "El parametro no puede ser nulo");
			#endregion
			_ConsumemoneyList.Add(obj);
		}
		

		#endregion //Public Functions

		#region Equals And HashCode Overrides
		/// <summary>
		/// local implementation of Equals based on unique value members
		/// </summary>
		public override bool Equals( object obj )
		{
			if( this == obj ) return true;
			if( ( obj == null ) || ( obj.GetType() != this.GetType() ) ) return false;
			User castObj = (User)obj; 
			return ( castObj != null ) &&
				( this._userid == castObj.Userid );
		}
		
		/// <summary>
		/// local implementation of GetHashCode based on unique value members
		/// </summary>
		public override int GetHashCode()
		{
			
			int hash = 57; 
			hash = 27 ^ hash ^ _userid.GetHashCode();
			return hash; 
		}
		#endregion
		
		#region IEquatable members

		public bool Equals(User other)
		{
			if (other == this)
				return true;
		
			return ( other != null ) &&
				( this._userid == other.Userid );
				   
		}

		#endregion
		
	}
}
